﻿using System;

namespace homework5
{
    class Solution
    {
        private static readonly int[] primes = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 };

        public void twoPrimeSum()
        {
            int PrimesCount = 25;
            for (int k = 6; k <= 100; k += 2)
            {
                bool found = false;
                for (int i = 0; i < PrimesCount; i++)
                {
                    for (int j = 0; j < PrimesCount; j++)
                    {
                        if (k == primes[i] + primes[j])
                        {
                            Console.WriteLine(k + "=" + primes[i] + "+" + primes[j]);
                            found = true;
                            break;
                        }
                    }
                    if (found)
                        break;
                }
            }
        }

        public void linqTest()
        {
            Random rnd = new Random();
            List<int> randomNums = new List<int>();

            Console.WriteLine("生成的随机数:");
            for (int i = 0; i < 100; i++)
            {
                int randomNumber = rnd.Next(0,1001);// 生成 0 到 1000 之间的随机整数
                Console.Write(randomNumber + " ");
                randomNums.Add(randomNumber);
            }
            Console.WriteLine();

            var sortN = from num in randomNums
                           orderby num descending
                           select num;

            List<int> list = sortN.ToList();
            Console.WriteLine("排序后的数组:");
            foreach(int num in list)
            {
                Console.Write(num+" ");
            }
            Console.WriteLine();

            Console.WriteLine("和为:" + sortN.Sum());
            Console.WriteLine("平均值为:"+sortN.Average());
        }

    }

    class Program
    {
        public static void Main(string[] args)//注意Main要大写M
        {
            Solution solution = new Solution();

            Console.WriteLine("将6~100内的所有偶数表示为为两个素数的和:");
            solution.twoPrimeSum();

            Console.WriteLine("----------------------------------------");

            Console.WriteLine("随机数测试");
            solution.linqTest();
        }
    }
}

